package com.ipt.frm.pw;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletMaestro
 */
public class ServletMaestro extends ServletBase {

	private static final long serialVersionUID = 3875930320125992722L;
	// TODO debe de estar en un unico sitio
	static final String INIT_PARAM_USER_NAME = "username";

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ServletMaestro() {
		super();

	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);

	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		// getServletContext().get

		/*
		 * Version AnderHttpSession session= req.getSession();
		 * if(session.getAttribute(INIT_PARAM_USER_NAME, loginUser)!=null){
		 * super.service(req,resp)}else{
		 * req.setAttribute("MSG","Usuario no logeado");
		 * req.getRequestDispatcher("login.jsp").forward(req,resp);}
		 */

		// TODO Auto-generated method stub
		if (req.getSession().getAttribute("username") == null) {

			// Usuario no logeado

			req.setAttribute(
					"MSG",
					new Mensaje(Tipo.INFO, propertiesMsg
							.getProperty("servlet.master.no.user")));
			req.getRequestDispatcher("login.jsp").forward(req, resp);

		} else {
			super.service(req, resp);
		}
	}

	@Override
	public void destroy() {
		super.destroy();

	}

	@Override
	public Properties getPropertiesMsg() {
		return propertiesMsg;
	}

}
